#!/bin/sh
#
# Run a simple backup  then do a
#   Virtual Full backup to another device.
#
# This script uses the disk autochanger
#
TestName="virtual-backup-test"
JobName=Vbackup
. scripts/functions


scripts/cleanup
scripts/copy-virtual-confs
scripts/prepare-disk-changer
change_jobname NightlySave $JobName

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/flat-c.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

#
# Note, we first backup into Pool Default,
#          then Migrate into Pool Full.
#              Pool Default forced to use Storage=DiskChanger
#              Pool Full    uses Storage=DiskChanger

# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
setdebug level=150 storage=DiskChanger
label storage=DiskChanger volume=ChangerVolume001 slot=1 Pool=Default drive=0
label storage=DiskChanger volume=ChangerVolume002 slot=2 Pool=Default drive=0
label storage=DiskChanger volume=ChangerVolume003 slot=3 Pool=Default drive=0
label storage=DiskChanger volume=ChangerVolume004 slot=4 Pool=Full drive=0
label storage=DiskChanger volume=ChangerVolume005 slot=5 Pool=Full drive=0
setdebug level=0 storage=DiskChanger
@# run several jobs
@exec "sh -c 'date > ${BackupDirectory}/date'"
run job=$JobName level=Full storage=DiskChanger yes
wait
messages
list jobs
list volumes
@exec "sh -c 'touch ${BackupDirectory}/*.c'"
run job=$JobName level=Incremental storage=DiskChanger yes
wait
messages
list jobs
list volumes
@exec "sh -c 'touch ${BackupDirectory}/*.c'"
run job=$JobName level=Differential storage=DiskChanger yes
wait
messages
list jobs
list volumes
@exec "sh -c 'date > ${BackupDirectory}/date'"
@exec "sh -c 'touch ${BackupDirectory}/*.c'"
run job=$JobName level=Incremental storage=DiskChanger yes
wait
messages
list jobs
list volumes
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/susan-restores select
unmark *
mark *
done
yes
wait
list jobs
list volumes
@#setdebug level=100 dir
@#
@# Now do a Virtual backup
@#
setdebug level=151 storage=DiskChanger
run job=$JobName level=VirtualFull storage=DiskChanger yes
wait
messages
list jobs
list volumes
@#
@# now do a restore of the Virtual backup
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/susan-restores select storage=DiskChanger
unmark *
mark *
done
yes
wait
@# Move Volume to Default pool
update Volume=ChangerVolume002
11
Default
list jobs
list volumes
messages
@exec "sh -c 'touch ${BackupDirectory}/*.c'"
@#
@# Do an incremental on top of the Virtual Full
@#
run job=$JobName level=Incremental storage=DiskChanger yes
wait
messages
list jobs
list volumes
@#
@# Now do another Consolidation
@#
setdebug level=150 storage=DiskChanger
run job=$JobName level=VirtualFull storage=DiskChanger yes
wait
messages
list volumes
list jobs
@#
@# now do a restore should restore from new Virtual backup
@#
@$out ${cwd}/tmp/log2.out
setdebug level=0 storage=DiskChanger
restore where=${cwd}/tmp/susan-restores select storage=DiskChanger
unmark *
mark *
done
yes
wait
list jobs
list volumes
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=DiskChanger
stop_susan

check_two_logs
check_restore_diff
end_test
